package com.yuntsg.ruiijn.controller.admin;


import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yuntsg.nnsfcp.common.utils.UserUtil;
import com.yuntsg.ruiijn.JiaXinZhi.JiaXinZhiIndexController;
import com.yuntsg.ruiijn.controller.system.InitController;
import com.yuntsg.ruiijn.database.entity.CheckFund;
import com.yuntsg.ruiijn.database.entity.SysQueen;
import com.yuntsg.ruiijn.database.entity.UnitBasic;
import com.yuntsg.ruiijn.database.entity.WosBasic;
import com.yuntsg.ruiijn.database.mapper.*;
import com.yuntsg.ruiijn.entity.IndexPicEntity;
import com.yuntsg.nnsfcp.common.beans.ResultBean;
import common.util.StringUtil;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.stream.Collectors;

import static com.yuntsg.ruiijn.JiaXinZhi.JiaXinZhiIndexController.*;

@RestController
@RequestMapping("admin_basic_index")
@Slf4j
@SuppressWarnings("ALL")
//@Api(tags = "后台首页信息")
public class AdminBasicIndexController {
    @Value("${upload.path}")
    public String uploadPath;
    @Autowired
    InitController initController;
    @Autowired
    private SysRoleMapper sysRoleMapper;
    @Autowired
    private UnitDeptMapper unitDeptMapper;
    @Autowired
    private UnitBasicMapper unitBasicMapper;
    @Autowired
    private WosBasicMapper wosBasicMapper;
    @Autowired
    private WosExtendMapper wosExtendMapper;
    @Autowired
    private WosBasicController wosBasicController;
    @Autowired
    private HttpSession session;
    @Autowired
    private CheckFundMapper checkFundMapper;
    @Autowired
    private SysQueenMapper sysQueenMapper;

    @Resource
    UserUtil userUtil;

    //@ApiOperation(value = "每秒获取分析完成的数据")
    @GetMapping("check_finish")
    public ResultBean<Object> check_finish() {
        int uid = userUtil.getUid();

        List<SysQueen> list = new LambdaQueryChainWrapper<>(sysQueenMapper)
                .eq(SysQueen::getUid, uid)//uid
                .eq(SysQueen::getCheckFlag, 0)//未显示的数据
                .eq(SysQueen::getStatus, 1).last(" limit 11").list();//已完成的数据
        for (SysQueen sysQueen : list) {
            WosBasic wosBasic = wosBasicMapper.selectById(sysQueen.getWosId());
            String cTi = wosBasic.getCTi();
            sysQueen.setCTi(cTi);
            sysQueen.setCopyFlag(wosBasic.getCopyFlag());
        }
        return new ResultBean<>(list);
    }


    //@ApiOperation(value = "00 返回可以选择的下拉菜单的基金名称")
//    @GetMapping("fund_list")
//    public ResultBean<Object> fund_list() {
////        Integer gid = sysUserMapper.selectById(userUtil.getUid()).getGid();
//        List<CheckFund> list = new LambdaQueryChainWrapper<>(checkFundMapper)
//                .select(CheckFund::getId, CheckFund::getCnName, CheckFund::getCount, CheckFund::getGid).isNotNull(CheckFund::getCnName)
//                .eq(CheckFund::getGid, gid)
//                .ne(CheckFund::getCnName, "")
//                .isNotNull(CheckFund::getCnName)
//                .orderByDesc(CheckFund::getCount)
//                .list();
//        List<String> collect = list.stream().map(CheckFund::getCnName).collect(Collectors.toList());
//        LinkedHashSet<Object> objects = new LinkedHashSet<>();
//        for (String s : collect) {
//            objects.add(s);
//        }
//        return new ResultBean<>(objects);
//    }


    //@ApiOperation(value = "01-单位基础信息")
    @GetMapping("unit_info")
    public ResultBean<Object> unit_info(Integer gid) {
        UnitBasic unitBasic = unitBasicMapper.selectById(gid);
        return new ResultBean<>(unitBasic);
    }











    //@ApiOperation(value = "点击柱状图查看具体的详情")
    @PostMapping("detail")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "ids", value = "1,2,3,4,5"),
//            @ApiImplicitParam(name = "page", value = "1"),
//            @ApiImplicitParam(name = "limit", value = "10"),
//    })
    public ResultBean<Object> detail(String ids, Integer page, Integer limit) {
        Page<WosBasic> basicPage = new LambdaQueryChainWrapper<>(wosBasicMapper).in(WosBasic::getId, ids.split(",")).page(new Page<>(page, limit));
        return new ResultBean<>(basicPage);
    }
}
